<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <router-link to='./gift_form/'>
      <el-button
        type="primary"
        icon="el-icon-plus"
        style="margin-left:0px"
      >添加</el-button>
      </router-link>
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="id" label="序号" width="70" :fixed="isMobile()?'left':undefined"/>
        <el-table-column align="center" prop="gift_name" label="礼物名称" width="180">
          <template slot-scope="scope">
            <el-input v-model="scope.row.gift_name"></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="gift_pic" label="礼物图片">
          <template slot-scope="scope">
            <upload-pic :thumb="tableData[scope.$index].gift_pic" @update:thumb="tableData[scope.$index].gift_pic=$event" width="100"/>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="gift_price" label="礼物金额" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.gift_price"></el-input>
          </template>
        </el-table-column>
       
       <el-table-column align="center" prop="gift_status" label="礼物状态" >
          <template slot-scope="scope">
            <el-button
              :type="scope.row.gift_status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'gift_status' ,scope.row.gift_status)"
            >{{ scope.row.gift_status === 1 ? "显示" : "不显示" }}</el-button>
          </template>
        </el-table-column>
         <el-table-column align="center" prop="gift_sort" label="排序" width="120">
          <template slot-scope="scope">
            <el-input v-model="scope.row.gift_sort"></el-input>
          </template>
        </el-table-column>
       
       <el-table-column align="center" prop="create_time" label="创建时间"  />
        <el-table-column
          align="center"
          prop="telephone"
          :fixed="isMobile()?undefined:'right'"
          label="操作"
        >
          <template slot-scope="scope">
            <!-- <router-link :to="'/ad_abt/ad/form?id=' + scope.row.id"> -->
              <el-button size="small" type="success"  @click="onSave(scope.row,scope.$index)">保存</el-button>
            <!-- </router-link> -->
            <el-button
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'live_gift_index',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入名字', field: 'title', val: '' }
      ],
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  activated(){
    if(this.$getUpdate()){
      this.onSearch()
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/LiveGift/index', form, 'POST').then(e => {
        this.tableData = e.data
        this.per_page = e.per_page
        this.total = e.total
        this.current_page = e.current_page
      })
    },
    onSave (obj) {
      //giftSave
      this.get('/admin/LiveGift/save', obj, 'POST').then(e => {
        console.log(e)
      })
    
    },
    
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, 'LiveGift').then(e => {
        e ? this.onSearch() : ''
      })
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/LiveGift/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
